package com.example.su_shi_tan_bas_lib.view.video_view.utils;


import com.example.su_shi_tan_bas_lib.global.AppGlobals;

public class NetInfoModuleManager {

    //网络监听
    private NetInfoModule mNetInfoModule;

    //网络状态
    private String mNetSate = "NORMAL";

    //是否发送了网络改变
    private boolean mNetChanged = false;

    private final static class ManagerHolder {
        private final static NetInfoModuleManager HOLDER = new NetInfoModuleManager();
    }

    public static NetInfoModuleManager getInstance() {
        return ManagerHolder.HOLDER;
    }

    private NetInfoModuleManager() {
    }

    /**
     * 监听网络状态
     */
    public void listenerNetWorkState() {
        if (mNetInfoModule != null) {
            mNetInfoModule.onHostResume();
        }
    }

    /**
     * 创建网络监听
     */
    public void createNetWorkState() {
        if (mNetInfoModule == null) {
            mNetInfoModule = new NetInfoModule(AppGlobals.getApplication(), state -> {
                if (!mNetSate.equals(state)) {

                    mNetChanged = true;
                }
                mNetSate = state;
            });
            mNetSate = mNetInfoModule.getCurrentConnectionType();
        }
    }

    /**
     * 取消网络监听
     */
    public void unListenerNetWorkState() {
        if (mNetInfoModule != null) {
            mNetInfoModule.onHostPause();
        }
    }

    /**
     * 释放网络监听
     */
    public void releaseNetWorkState() {
        if (mNetInfoModule != null) {
            mNetInfoModule.onHostPause();
            mNetInfoModule = null;
        }
    }
}
